const errorHandler = (error) => {
  if (error.response) {
    // The request was made and the server responded with a status code
    // that falls out of the range of 2xx
  } else {
    // The request was made but no response was received or error occurs when setting up the request.
  }

  throw error; // If throw. The error will continue to be thrown.
};

const requestInterceptor = (url, options) => {
  const token = localStorage.getItem('access_token');
  const headers = { Authorization: `Bearer ${token}` };
  return {
    url,
    options: { ...options, interceptors: true, headers },
  };
};

const responseInterceptor = async (response) => {
  // const res = await response.clone().json();
  // if (res.code === 200) {
  //   return res.data;
  // }
  return response;
};

export { errorHandler, requestInterceptor, responseInterceptor };
